package com.quanyan.place.service.impl;

import com.quanyan.common.utils.DateUtils;
import com.quanyan.place.constants.PlaceConstants;
import com.quanyan.place.entity.TbBizPlacePeriod;
import com.quanyan.place.entity.TbBizPlacePeriodExample;
import com.quanyan.place.entity.TbBizPlaceRepresent;
import com.quanyan.place.entity.TbBizPlaceRepresentExample;
import com.quanyan.place.entity.apiresp.RespBizPeriodInfo;
import com.quanyan.place.mapper.TbBizPlacePeriodMapper;
import com.quanyan.place.mapper.TbBizPlaceRepresentMapper;
import com.quanyan.place.service.PeriodService;
import com.quanyan.place.service.RepresentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;


/**
 * Created by Administrator on 2016/4/14 0014.
 */
@Service("representService")
public class RepresentServiceImpl implements RepresentService {

    @Autowired
    TbBizPlaceRepresentMapper tbBizPlaceRepresentMapper;


    @Override
    public TbBizPlaceRepresent getRepresentInfoByPlaceId(Integer placeId,Integer isEffective) {
        TbBizPlaceRepresentExample example =new TbBizPlaceRepresentExample();
        TbBizPlaceRepresentExample.Criteria criteria=example.createCriteria();
        criteria.andPlaceIdEqualTo(placeId);
        byte bt = (byte)isEffective.intValue();
        criteria.andIsEffectiveEqualTo(bt);
       List<TbBizPlaceRepresent> list= tbBizPlaceRepresentMapper.selectByExample(example);
      if (null != list && list.size()>0){
         return  list.get(0);
      } else {
          return null;
      }
    }

    @Override
    public List<Integer> getPlaceIdsByRepresent(String bussinessRepresent,Integer isEffective) {
        TbBizPlaceRepresentExample example =new TbBizPlaceRepresentExample();
        TbBizPlaceRepresentExample.Criteria criteria=example.createCriteria();
        criteria.andBusinessRepresentLike("%"+bussinessRepresent+"%");
        byte bt = (byte)isEffective.intValue();
        criteria.andIsEffectiveEqualTo(bt);
        List<TbBizPlaceRepresent> list= tbBizPlaceRepresentMapper.selectByExample(example);
       List<Integer> listInt=new ArrayList<Integer>();
        if ( null != list && list.size()>0){
            for (TbBizPlaceRepresent r:list){
                listInt.add(r.getPlaceId());
            }
        }
        return listInt;
    }


}
